<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.prime.com.tr/ui">

<!-- 
		Replace path to template, title, header and body
		with actual data.
	 -->
<ui:composition template="../template/layout.xhtml">
	<ui:define name="titulo">#{cadEmpresaController.tituloPagina}</ui:define>

	<ui:define name="frConteudo">
		<h:form id="form">
			<!-- 
							<h:outputLabel value="" />
							<h:inputHidden value="#{cadEmpresaController.infoBean.id}" />
							-->
			<h:panelGrid columns="1" border="0" height="100%">

				<!-- bloco de edição -->
				<p:panel header="#{cadEmpresaController.tituloPagina}"
					rendered="#{cadEmpresaController.estadoCrud}">
					<h:panelGrid border="0" columns="2">
						<f:facet name="header">
							<p:messages id="msgErro" />
						</f:facet>

						<h:outputLabel value="#{msg.cadEmpresa}" for="empresa" />
						<h:inputText id="empresa" label="#{msg.cadEmpresa}"
							value="#{cadEmpresaController.infoBean.nome}"
							required="true"
							requiredMessage="#{msg.cadEmpresaRequiredMessage}" />
						
						<h:outputLabel value="#{msg.cadEmpresaNif}" for="nif" />
						<h:inputText id="nif" label="#{msg.cadEmpresa}"
							value="#{cadEmpresaController.infoBean.nif}" />

						<h:outputLabel value="#{msg.cadEmpresaActivo}" for="activo" />
						<h:selectBooleanCheckbox id="activo"
							label="#{msg.cadEmpresaActivo}"
							value="#{cadEmpresaController.infoBean.activo}" />
						
						<h:outputLabel value="#{msg.cadEmpresaRepresentante}" for="representante" />
						<h:inputText id="representante" label="#{msg.cadEmpresaRepresentante}"
							value="#{cadEmpresaController.infoBean.representante}" required="true" 
							requiredMessage="#{msg.locProvinciaRequiredMessage}" />

						<h:outputLabel value="#{msg.locProvincia}" for="provincia" />
						<h:selectOneMenu id="provincia"
							value="#{cadEmpresaController.infoBean.localEscritorio.provincia}"
							valueChangeListener="#{cadEmpresaController.cbProvinciaChanged}"
							onchange="submit()" immediate="true" required="true" 
							requiredMessage="#{msg.locProvinciaRequiredMessage}">
							<f:selectItems id="provinciaItems"
								value="#{locProvinciaController.itemsAvailableSelectOneByPais}" />
						</h:selectOneMenu>

						<h:outputLabel value="#{msg.locMunicipio}" for="municipio" />
						<h:selectOneMenu id="municipio"
							value="#{cadEmpresaController.infoBean.localEscritorio}" 
							required="true" 
							requiredMessage="#{msg.locMunicipioRequiredMessage}">
							<f:selectItems id="municipioItems"
								value="#{locMunicipioController.itemsAvailableSelectOne}" />
						</h:selectOneMenu>

						<h:outputLabel value="#{msg.cadEmpresaEndereco}" for="endereco" />
						<h:inputText id="endereco" label="#{msg.cadEmpresaEndereco}"
							value="#{cadEmpresaController.infoBean.endereco}"
							required="true"
							requiredMessage="#{msg.cadEmpresaEnderecoRequiredMessage}" />
							
						<h:outputLabel value="#{msg.cadEmpresaTelefone}" for="telefone" />
						<h:inputText id="telefone" label="#{msg.cadEmpresaTelefone}"
							value="#{cadEmpresaController.infoBean.telefone}"
							required="true"
							requiredMessage="#{msg.cadEmpresaTelefoneRequiredMessage}" />

						<h:outputLabel value="#{msg.cadEmpresaFax}" for="fax" />
						<h:inputText id="fax" label="#{msg.cadEmpresaFax}"
							value="#{cadEmpresaController.infoBean.fax}"
							required="true" />

						<h:outputLabel value="#{msg.cadEmpresaEmail}" for="email" />
						<h:inputText id="email" label="#{msg.cadEmpresaEmail}"
							size="50" maxlength="50"
							value="#{cadEmpresaController.infoBean.email}"
							required="true"
							requiredMessage="#{msg.authUtilizadorEmailRequiredMessage}"
							validatorMessage="#{msg.authUtilizadorEmailValidatorMessage}">
							<f:validateRegex pattern="[a-zA-Z0-9\-\_\.]+@[a-zA-Z0-9\-\_\.]+" />
						</h:inputText>

						<h:outputLabel value="#{msg.cadEmpresaSite}" for="site" />
						<h:inputText id="site" label="#{msg.cadEmpresaSite}"
							value="#{cadEmpresaController.infoBean.site}" />
							
						<f:facet name="footer">
							<h:panelGroup>
								<center><h:commandButton id="salvarButton"
									value="#{msg.salvarButton}"
									action="#{cadEmpresaController.adicionar}"
									rendered="#{cadEmpresaController.estadoAdicionar}" /> <h:commandButton
									id="alterarButton" value="#{msg.alterarButton}"
									action="#{cadEmpresaController.editar}"
									rendered="#{cadEmpresaController.estadoActualizar}" /> <h:commandButton
									id="eliminarButton" value="#{msg.eliminarButton}"
									action="#{cadEmpresaController.eliminar}"
									rendered="#{cadEmpresaController.estadoEliminar}"
									onclick="if(!confirm('Confirma a exclusão do registo?')) return false;" />
								<h:commandButton id="limparButton" value="#{msg.limparButton}"
									type="reset"
									rendered="#{cadEmpresaController.estadoAdicionar}" /> <h:commandButton
									id="cancelarButton" value="#{msg.cancelarButton}"
									action="#{cadEmpresaController.voltar}" immediate="true" /></center>
							</h:panelGroup>
						</f:facet>
					</h:panelGrid>
				</p:panel>
				<!-- fim do bloco de edição -->
			</h:panelGrid>
			<br />
			<h:panelGroup>
				<h:commandLink action="#{cadEmpresaController.voltar}"
					immediate="true" value="#{msg.geralLinkListaRegistos}" />
				<h:outputText value="  " />
				<h:commandLink action="#{cadEmpresaController.voltar}"
					immediate="true" value="#{msg.geralVoltar}" />
			</h:panelGroup>
		</h:form>
	</ui:define>
</ui:composition>
</html>
